package com.mjfeed.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mjfeed.entity.Area;
import com.mjfeed.service.AreaService;
import com.mjfeed.util.Pagination;
import com.mjfeed.util.ParamBean;
import com.mjfeed.util.QueryCondition;

@Service("areaService")
public class AreaServiceImpl extends BaseServiceImpl implements AreaService {
	@Transactional(readOnly = true)
	public List<Area> findRoots(Integer count) {
		ParamBean paramBean = new ParamBean();
		if (count != null && count > 0) {
			paramBean.setPageSize(count);
		}
		List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
		queryConditions.add(new QueryCondition("parent is null"));
		String orderBy = "order by orders asc";
		Pagination<Area> pagination = (Pagination<Area>)getPagination(Area.class, queryConditions, orderBy, paramBean.getPage(), paramBean.getPageSize());
		if (pagination != null && pagination.getRecordList() != null && pagination.getRecordList().size() > 0) {
			return pagination.getRecordList();
		} else {
			return null;
		}
		
	}

}
